<?php
/**
 * Контролер ошибок.
 * @author nrnwest@gmail.com
 *
 */
class ErrorController extends Zend_Controller_Action
{
    /**
     * Установка темы для ошибок в системе.
     */
    public function preDispatch()
    {
        $theme = new Arm_Themes();
        $theme->setOtherThemeModule('default', 'error');
    }
    
    /**
     * Вывод ошибок в системе.
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        
        $this->view->type = get_class($errors->exception);
        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
               
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
                break;
            default:
                // application error
                $code = (int)$errors->exception->getCode();
                if($code === 0) {
                   $code = 500;
                }
                // проверка кода если ошибочный код выставим 500
                if (100 > $code or 599 < $code) {
                    $code = 500;
                }
                $this->getResponse()->setHttpResponseCode($code);
                $this->view->message = 'Application error';
                break;
        }

        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;
    }


}

